﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nanoCMS.Forum.Concrete;
using nanoCMS.Forum.WebUI.Models.AdminViewModels;
using nanoCMS.Forum.WebUI.Models.ViewModels;

namespace nanoCMS.Forum.WebUI.Models
{
    public static class VMFactory
    {
        public static ForumEntryVM ForumEntryVMFactory(Concrete.Forum forum)
        {
            return new ForumEntryVM
            {
                ForumID = forum.ForumID,
                Title = forum.Title,
                Description = forum.Description,
                ParentForumID = forum.ParentForumID,
                Order = forum.Order
            };
        }

        public static ForumVM ForumVMFactory(Concrete.Forum forum)
        {
            return new ForumVM
            {
                ForumID = forum.ForumID,
                ParentForumID = forum.ParentForumID,
                Title = forum.Title,
                Description = forum.Description,
                ThreadsCount = forum.ThreadsCount,
                PostsCount = forum.PostsCount
            };
        }

        public static ThreadVM ThreadVMFactory(Concrete.Thread thread)
        {
            return new ThreadVM
            {
                ThreadID= thread.ThreadID,
                ThreadPostID = thread.ThreadPostID.HasValue ? thread.ThreadPostID.Value : 0,
                Title = thread.Title,
                Description = thread.Description,
                PostsCount = thread.PostsCount,
                ViewsCount = thread.ViewsCount,
                ForumID = thread.ForumID.HasValue ? thread.ForumID.Value : 0,
                IsClosed = thread.IsClosed,
                LastPostId = thread.LastPostID.HasValue ? thread.LastPostID.Value : 0
            };
        }

        public static PostVM PostVMFactory(Post post)
        {
            return new PostVM
            {
                PostID = post.PostID,
                Title = post.Title,
                Content = post.Content,
                PostTime = post.PostTime,
                UserID = post.UserID,
                ThreadID = post.ThreadID.HasValue ? post.ThreadID.Value : 0
            };
        }

        public static PostUserVM PostUserFactory(Core.Concrete.User user)
        {
            return new PostUserVM()
            {
                DisplayName = user.GetDisplayName(),
                UserID = user.UserID
            };
        }

        public static ForumUserInfoVM ForumUserInfoFactory(ForumUserInfo info)
        {
            return new ForumUserInfoVM()
            {
                PostCount = info.PostCount
            };
        }
    }
}
